/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HistoriaClinica.java
 *
 * Created on 19/06/2011, 23:38:00
 *
 * 1.1 Franco Funcionalidad inicial para registrar una enfermedad
 */
package visuales;

import entidades.Animal;
import entidades.Bateria;
import entidades.Camara;
import entidades.Enfermedad;
import entidades.Jaula;
import entidades.TipoCamara;
import entidades.TipoEvento;
import gestores.GestorProduccion;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Facundo
 */
public class HistoriaClinica extends javax.swing.JFrame {

    private JFrame pantalla;
    private GestorProduccion gp;
    private int evento;
    private Animal madre;
    private Animal padre;
    private String ubicacion;
    private Animal animal;

    /** Creates new form HistoriaClinica */
    public HistoriaClinica(JFrame padre, int flap) {
        initComponents();
        gp = new GestorProduccion();
        jTabbedPane1.setSelectedIndex(flap);
        this.pantalla = padre;
        this.tomarEvento(flap);
        if (evento == TipoEvento.ENFERMEDAD) {
            this.cargarComboEnfermedad();
        }
    }

    private void tomarEvento(int flap) {
        String titulo = jTabbedPane1.getTitleAt(flap);
        if (titulo.compareToIgnoreCase("Enfermedad") == 0) {
            this.setEvento(TipoEvento.ENFERMEDAD);
        } else {
            this.setEvento(TipoEvento.CURACION);
        }
    }

    public int getEvento() {
        return evento;
    }

    public void setEvento(int evento) {
        this.evento = evento;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        txtAnimal = new javax.swing.JLabel();
        btnRegistrarEnfermedad = new javax.swing.JButton();
        btnCancelarEnfermedad = new javax.swing.JButton();
        lblEnfermedad = new javax.swing.JLabel();
        cmbEnfermedad = new javax.swing.JComboBox();
        lblFecha = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAObservacionesEnfermedad = new javax.swing.JTextArea();
        jPanel7 = new javax.swing.JPanel();
        lblMadre2 = new javax.swing.JLabel();
        lblPadre3 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        lblMadreEnfermedad = new javax.swing.JLabel();
        lblPadreEnfermedad = new javax.swing.JLabel();
        lblUbicacioneEnfermedad = new javax.swing.JLabel();
        txtAnimalEnfermedad = new javax.swing.JTextField();
        btnBuscarAnimalEnfermedad = new javax.swing.JButton();
        txtFechaDeteccionEnfermedad = new javax.swing.JFormattedTextField();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        lblEnfermedad1 = new javax.swing.JLabel();
        cmbEnfermedadCuracion = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtAObservacionesCuracion = new javax.swing.JTextArea();
        jLabel7 = new javax.swing.JLabel();
        btnRagistrarCuracion = new javax.swing.JButton();
        btnCancelarCuracion = new javax.swing.JButton();
        lblEnfermedadDetectada = new javax.swing.JLabel();
        txtAnimal1 = new javax.swing.JLabel();
        txtAnimalCuracion = new javax.swing.JTextField();
        btnBuscarAnimalCuracion = new javax.swing.JButton();
        jPanel10 = new javax.swing.JPanel();
        lblMadre4 = new javax.swing.JLabel();
        lblPadre5 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        lblMadreCuracion = new javax.swing.JLabel();
        lblPadreCuracion = new javax.swing.JLabel();
        lblUbicacionCuracion = new javax.swing.JLabel();
        btnSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("PampaChin-Historia Clinica");

        txtAnimal.setText("Animal:");

        btnRegistrarEnfermedad.setText("Registrar");
        btnRegistrarEnfermedad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRegistrarEnfermedadActionPerformed(evt);
            }
        });

        btnCancelarEnfermedad.setText("Cancelar");

        lblEnfermedad.setText("Enfermedad:");

        lblFecha.setText("Fecha detección:");

        jLabel4.setText("Observaciones:");

        txtAObservacionesEnfermedad.setColumns(20);
        txtAObservacionesEnfermedad.setRows(5);
        jScrollPane1.setViewportView(txtAObservacionesEnfermedad);

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Animal", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        lblMadre2.setText("Madre :");

        lblPadre3.setText("Padre :");

        jLabel6.setText("Ubicacion:");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblMadre2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblUbicacioneEnfermedad, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(lblMadreEnfermedad, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblPadre3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblPadreEnfermedad, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(39, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblMadre2)
                    .addComponent(lblMadreEnfermedad, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPadre3)
                    .addComponent(lblPadreEnfermedad, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(lblUbicacioneEnfermedad, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        btnBuscarAnimalEnfermedad.setText("Buscar");
        btnBuscarAnimalEnfermedad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarAnimalEnfermedadActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(txtAnimal)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtAnimalEnfermedad, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btnBuscarAnimalEnfermedad, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(lblEnfermedad)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cmbEnfermedad, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(lblFecha)
                            .addGap(18, 18, 18)
                            .addComponent(txtFechaDeteccionEnfermedad))
                        .addComponent(jLabel4)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(btnRegistrarEnfermedad)
                            .addGap(13, 13, 13)
                            .addComponent(btnCancelarEnfermedad)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 443, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtAnimal)
                    .addComponent(txtAnimalEnfermedad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBuscarAnimalEnfermedad))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEnfermedad)
                    .addComponent(cmbEnfermedad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblFecha)
                    .addComponent(txtFechaDeteccionEnfermedad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelarEnfermedad)
                    .addComponent(btnRegistrarEnfermedad))
                .addGap(35, 35, 35))
        );

        jTabbedPane1.addTab("Enfermedad", jPanel1);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(" Enfermedades que padece"));

        lblEnfermedad1.setText("Enfermedad:");

        txtAObservacionesCuracion.setColumns(20);
        txtAObservacionesCuracion.setRows(5);
        jScrollPane2.setViewportView(txtAObservacionesCuracion);

        jLabel7.setText("Observaciones:");

        btnRagistrarCuracion.setText("Registrar");
        btnRagistrarCuracion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRagistrarCuracionActionPerformed(evt);
            }
        });

        btnCancelarCuracion.setText("Cancelar");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(lblEnfermedad1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblEnfermedadDetectada, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(cmbEnfermedadCuracion, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel7)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(btnRagistrarCuracion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancelarCuracion)))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEnfermedad1)
                    .addComponent(cmbEnfermedadCuracion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblEnfermedadDetectada, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnRagistrarCuracion)
                    .addComponent(btnCancelarCuracion))
                .addContainerGap())
        );

        txtAnimal1.setText("Animal:");

        btnBuscarAnimalCuracion.setText("Buscar");
        btnBuscarAnimalCuracion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarAnimalCuracionActionPerformed(evt);
            }
        });

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Animal", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        lblMadre4.setText("Madre :");

        lblPadre5.setText("Padre :");

        jLabel11.setText("Ubicacion:");

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblMadre4, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(lblMadreCuracion, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(251, 251, 251))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblUbicacionCuracion, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                            .addGroup(jPanel10Layout.createSequentialGroup()
                                .addGap(141, 141, 141)
                                .addComponent(lblPadre5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblPadreCuracion, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)))
                        .addContainerGap())))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPadre5)
                    .addComponent(lblMadre4)
                    .addComponent(lblMadreCuracion, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPadreCuracion, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(lblUbicacionCuracion, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(txtAnimal1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtAnimalCuracion, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBuscarAnimalCuracion, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel6, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtAnimal1)
                    .addComponent(txtAnimalCuracion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBuscarAnimalCuracion))
                .addGap(11, 11, 11)
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Curacion", jPanel4);

        btnSalir.setText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 476, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(443, Short.MAX_VALUE)
                .addComponent(btnSalir)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 432, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnSalir)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        this.dispose();
        pantalla.setVisible(true);
    }//GEN-LAST:event_btnSalirActionPerformed

    private void btnBuscarAnimalEnfermedadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarAnimalEnfermedadActionPerformed
        boolean res = this.buscarAnimal(txtAnimalEnfermedad.getText().toUpperCase());
        if (res != false) {
            this.txtFechaDeteccionEnfermedad.setText(String.valueOf(this.gp.tomarFechaSistema().dateValue()));
            this.mostrarDatosEnfermedad();
        }
    }//GEN-LAST:event_btnBuscarAnimalEnfermedadActionPerformed

    private void btnRegistrarEnfermedadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegistrarEnfermedadActionPerformed
        this.tomarConfirmacion(true);
    }//GEN-LAST:event_btnRegistrarEnfermedadActionPerformed

    private void btnBuscarAnimalCuracionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarAnimalCuracionActionPerformed
        boolean res = this.mostrarEnfermedad(txtAnimalCuracion.getText().toUpperCase());
        if (res != false) {
            this.buscarAnimal(txtAnimalCuracion.getText().toUpperCase());
            this.mostrarDatosCuracion();
        }
    }//GEN-LAST:event_btnBuscarAnimalCuracionActionPerformed

    private void btnRagistrarCuracionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRagistrarCuracionActionPerformed
        this.tomarConfirmacion(true);
    }//GEN-LAST:event_btnRagistrarCuracionActionPerformed
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new HistoriaClinica().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscarAnimalCuracion;
    private javax.swing.JButton btnBuscarAnimalEnfermedad;
    private javax.swing.JButton btnCancelarCuracion;
    private javax.swing.JButton btnCancelarEnfermedad;
    private javax.swing.JButton btnRagistrarCuracion;
    private javax.swing.JButton btnRegistrarEnfermedad;
    private javax.swing.JButton btnSalir;
    private javax.swing.JComboBox cmbEnfermedad;
    private javax.swing.JComboBox cmbEnfermedadCuracion;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lblEnfermedad;
    private javax.swing.JLabel lblEnfermedad1;
    private javax.swing.JLabel lblEnfermedadDetectada;
    private javax.swing.JLabel lblFecha;
    private javax.swing.JLabel lblMadre2;
    private javax.swing.JLabel lblMadre4;
    private javax.swing.JLabel lblMadreCuracion;
    private javax.swing.JLabel lblMadreEnfermedad;
    private javax.swing.JLabel lblPadre3;
    private javax.swing.JLabel lblPadre5;
    private javax.swing.JLabel lblPadreCuracion;
    private javax.swing.JLabel lblPadreEnfermedad;
    private javax.swing.JLabel lblUbicacionCuracion;
    private javax.swing.JLabel lblUbicacioneEnfermedad;
    private javax.swing.JTextArea txtAObservacionesCuracion;
    private javax.swing.JTextArea txtAObservacionesEnfermedad;
    private javax.swing.JLabel txtAnimal;
    private javax.swing.JLabel txtAnimal1;
    private javax.swing.JTextField txtAnimalCuracion;
    private javax.swing.JTextField txtAnimalEnfermedad;
    private javax.swing.JFormattedTextField txtFechaDeteccionEnfermedad;
    // End of variables declaration//GEN-END:variables

    private boolean buscarAnimal(String nombreAnimal) {
        Animal res_animal = this.gp.getAnimal(nombreAnimal);
        if (res_animal != null) {
            this.animal = res_animal;
            this.gp.setAnimalSeleccionado(this.getAnimal());
            if (this.getAnimal().getMadre() != null && this.getAnimal().getPadre() != null) {
                this.madre = this.getAnimal().getMadre();
                this.padre = this.getAnimal().getPadre();
            } else {
                this.madre = new Animal();
                this.madre.setNombre("S/D");
                this.padre = new Animal();
                this.padre.setNombre("S/D");
            }
            Camara res_camara = this.getAnimal().getUbicacion();
            if (res_camara != null) {
                TipoCamara res_tipoCamara = res_camara.getTipo_camara();
                Bateria res_bateria = (Bateria) this.getAnimal().getUbicacion().getBateria().get(0);
                Jaula res_jaula = res_bateria.getJaula().get(0);
                this.ubicacion = res_camara.getNombre()
                        + " - " + res_tipoCamara.getNombre()
                        + " - " + res_bateria.getNombre()
                        + " - " + res_jaula.getNombre();
            } else {
                this.ubicacion = "S/D";
            }
            return true;
        } else {
            this.mensajeError(btnRegistrarEnfermedad, "Animal no existnte.");
            return false;
        }
    }

    private Animal getAnimal() {
        return this.animal;
    }

    private String getNombreMadre() {
        return this.madre.getNombre();
    }

    private String getNombrePadre() {
        return this.padre.getNombre();
    }

    private String getUbicacionAnimal() {
        return ubicacion;
    }

    private void mensajeError(JButton boton, String msg) {
        if (boton != null) {
            boton.setEnabled(false);
        }
        if (msg != null) {
            System.out.println("Error: " + msg);
            JOptionPane.showMessageDialog(null, msg, "Atencion", JOptionPane.ERROR_MESSAGE);
        }
        return;
    }

    private void cargarComboEnfermedad() {
        ArrayList res_enfermedades = this.gp.allEnfermedad();
        Iterator iter_resEnfermedad = res_enfermedades.iterator();
        Enfermedad res_enfermedad = null;
        while (iter_resEnfermedad.hasNext()) {
            res_enfermedad = (Enfermedad) iter_resEnfermedad.next();
            cmbEnfermedad.addItem(res_enfermedad);
        }
    }

    private void tomarConfirmacion(boolean acepto) {
        String res = "FAIL";
        String msg="";
        System.out.println("Confirmando acciones: " + acepto);
        if (this.getEvento() == TipoEvento.ENFERMEDAD) {
            if (txtAObservacionesEnfermedad.getText().compareToIgnoreCase("") != 0) {
                this.gp.setObservacionVarias(txtAObservacionesEnfermedad.getText());
            }
            this.gp.setEnfermedad((Enfermedad) cmbEnfermedad.getSelectedItem());
            res = this.gp.confirmacionAceptada(acepto, this.getEvento());
            msg="Fallo la registracion de la enfermedad del animal.";
        }
        if(this.getEvento()==TipoEvento.CURACION){
            if(txtAObservacionesCuracion.getText().compareToIgnoreCase("")!=0){
                this.gp.setObservacionVarias(txtAObservacionesCuracion.getText());
            }
            res=this.gp.confirmacionAceptada(acepto, this.getEvento());
            msg="No se pudo registrar la curacion del animal.";
        }
        if (res.compareToIgnoreCase("OK") == 0) {
            JOptionPane.showMessageDialog(null, res, "Resultado", JOptionPane.INFORMATION_MESSAGE);
        } else {
            this.mensajeError(null, msg);
        }
        this.dispose();
        this.pantalla.setVisible(true);
    }

    private void mostrarDatosEnfermedad() {
        lblMadreEnfermedad.setText(this.getNombreMadre());
        lblPadreEnfermedad.setText(this.getNombrePadre());
        lblUbicacioneEnfermedad.setText(this.getUbicacionAnimal());
    }

    private void mostrarDatosCuracion() {
        lblMadreCuracion.setText(this.getNombreMadre());
        lblPadreCuracion.setText(this.getNombrePadre());
        lblUbicacionCuracion.setText(this.getUbicacionAnimal());
    }

    private boolean mostrarEnfermedad(String nombreAnimal) {
        boolean res = false;
        Animal res_animal = new Animal();
        res_animal.setNombre(nombreAnimal);
        String enfermedad = "S/D";
        Enfermedad res_enfermedad = this.gp.buscarEnfermedad(res_animal);
        if (res_enfermedad != null) {
            enfermedad = res_enfermedad.getNombre();
            lblEnfermedadDetectada.setText(enfermedad);
            res = true;
        } else {
            this.mensajeError(btnRagistrarCuracion, "El animal a buscar no posee enfermedad");
            this.dispose();
            this.pantalla.setVisible(true);
        }
        return res;
    }
}
